//使用懒加载 
import { lazy } from 'react'
// 路由跳转
import { Navigate } from 'react-router-dom'
// 处理路由懒加载的白屏问题
import LazyRouter from './LazyRouter.jsx'
// 引入组件路径(登录和NotFound一般不需要懒加载)
const Layout = lazy(() => import('@/pages/layout/index.jsx'))
const Login = lazy(() => import('@/pages/login/index.jsx'))
const NotFound = lazy(() => import('@/pages/404.jsx'))
const Index = lazy(() => import('@/pages/dashboard/index1'))
const Index2 = lazy(() => import('@/pages/dashboard/index2'))

const istoken = sessionStorage.getItem('token')

const routerList = [
  {
    // 主页
    path: '/',
    //auth：进入路由是否需要token验证
    //title：该页的页面标题
    //主页面必须要嵌套路由，第一个空路由可以自动跳转到某个路由
    element: <Navigate to={'/dashboard/workplace'}></Navigate>
  },
  {
    // 首页
    path: '/dashboard',
    element: <LazyRouter element={<Layout />} title="主页面"></LazyRouter>,
    children: [
      {
        path: 'workplace',
        element: <LazyRouter element={<Index />} title="工作台" ></LazyRouter>
      },
      // {
      //   path: 'index2',
      //   element: <LazyRouter element={<Index2 />} title="页面2"></LazyRouter>
      // }
    ]
  },
  {
    // 登录页
    path: '/login',
    element: istoken ? <Navigate to={'/'} /> : <Login title="登录"></Login>
    // element: <Navigate element={<Login />} title="登录"></Navigate>
  },
  {
    // 空页
    path: '/404',
    element: <LazyRouter element={<NotFound />} title="找不到网页"></LazyRouter>
  },
  {
    // 找不到
    path: '*',
    element: <Navigate to={'/404'}></Navigate>
  },
]
export default routerList
